package com.ysd.lis.service.cri.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.entity.cri.CriWarningConfig;
import com.ysd.lis.mapper.cri.CriWarningConfigMapper;
import com.ysd.lis.service.cri.CriWarningConfigService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wh
 * @since 2025-02-17
 */
@Service
public class CriWarningConfigServiceImpl extends ServiceImpl<CriWarningConfigMapper, CriWarningConfig> implements CriWarningConfigService {

    @Override
    public Result saveOrUpdateConfig(CriWarningConfig criWarningConfig) {

        this.remove(new LambdaQueryWrapper<CriWarningConfig>().eq(CriWarningConfig::getMacUrl,criWarningConfig.getMacUrl()));
        boolean save = this.saveOrUpdate(criWarningConfig,new LambdaQueryWrapper<CriWarningConfig>().eq(CriWarningConfig::getMacUrl,criWarningConfig.getMacUrl()).eq(CriWarningConfig::getDelFlag,0));
        if (save) {
            return Result.succ(1, "成功！", null);
        } else {
            return Result.fail("失败！");
        }
    }

    @Override
    public Result getInfoByMac(String macUrl) {
        List<CriWarningConfig> criWarningConfig = this.list(new LambdaQueryWrapper<CriWarningConfig>().eq(CriWarningConfig::getMacUrl,macUrl).eq(CriWarningConfig::getDelFlag,0));
        if(CollectionUtils.isNotEmpty(criWarningConfig)){
            return Result.succ(criWarningConfig.get(0));
        }
        return Result.succ(null);
    }
}
